package org.example.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dao.ResultsInfoDao;
import org.example.entity.ResultsInfoEntity;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public  class ResultServiceImpl extends ServiceImpl<ResultsInfoDao, ResultsInfoEntity>
        implements ResultsInfoService {



        //根据考试ID和学生ID找出学生的试卷答案
        public List<ResultsInfoEntity> getResultsByESId(long examId,long studentId) {
            QueryWrapper<ResultsInfoEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("exam_id", examId);
            queryWrapper.eq("student_id", studentId);
            return baseMapper.selectList(queryWrapper);
        }
        public  ResultsInfoEntity getResultsByQuestionId(long questionId, long studentId){
            QueryWrapper<ResultsInfoEntity> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("question_id", questionId);
            queryWrapper.eq("student_id", studentId);
            return baseMapper.selectOne(queryWrapper);
        }
        public boolean saveResult(ResultsInfoEntity result) {
            return baseMapper.insert(result) > 0;
      }

      @Override
       public boolean deleteResultById(Integer resultId) {
      return false;
        }


        public boolean deleteResultById(long resultId) {
            return baseMapper.deleteById(resultId) > 0;
        }



        }



